package com.dundun.SSO.manage.impl;

import com.dundun.SSO.core.impl.BaseServiceImpl;
import com.dundun.SSO.manage.ISsoGroupRoleRelationService;
import com.dundun.SSO.manage.ISsoGroupService;
import com.dundun.SSO.manage.dao.SsoGroupRoleRelationDao;
import com.dundun.SSO.manage.pojo.SsoGroup;
import com.dundun.SSO.manage.pojo.SsoGroupRoleRelation;
import com.dundun.SSO.manage.query.SsoGroupRoleRelationQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**********************************************************
 * 版权所有：搜影科技 保留所有权利
 * 创建日期: 2017/5/6 0006 10:48
 * 创建作者: gezhangkai
 * 版    本:
 * 功    能:
 * 最后修改时间:
 * 修改记录:
 ***********************************************************/
@Service
public class SsoGroupRoleRelationServiceImpl extends BaseServiceImpl<SsoGroupRoleRelation> implements ISsoGroupRoleRelationService {
    @Autowired
    private SsoGroupRoleRelationDao ssoGroupRoleRelationDao;

    @Autowired
    private ISsoGroupService ssoGroupService;

    public List<SsoGroupRoleRelation> selectByPage(SsoGroupRoleRelationQuery ssoGroupRoleRelationQuery) {
        return ssoGroupRoleRelationDao.selectByPage(ssoGroupRoleRelationQuery);
    }

    public Integer selectCountByPage(SsoGroupRoleRelationQuery ssoGroupRoleRelationQuery) {
        return ssoGroupRoleRelationDao.selectCountByPage(ssoGroupRoleRelationQuery);
    }

    public List<SsoGroupRoleRelation> selectAllRelationByGroupId(Long groupId) {

        List<SsoGroup> ssoGroupList = new ArrayList<>();
        ssoGroupList.add(ssoGroupService.selectByPrimaryKey(groupId));
        ssoGroupList.addAll(ssoGroupService.selectAllParentGroup(groupId));
        List<SsoGroupRoleRelation> ssoGroupRoleRelationList = new ArrayList<>();
        for (SsoGroup ssoGroup : ssoGroupList) {
            Example example = new Example(SsoGroupRoleRelation.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("groupId", ssoGroup.getId());
            ssoGroupRoleRelationList.addAll(ssoGroupRoleRelationDao.selectByExample(example));
        }
        return ssoGroupRoleRelationList;
    }
}
